//
//  EmptyView.swift
//  NEContactUIKit
//
//  Created by Laura on 2024/8/2.
//

@objcMembers
open class NEBaseEmptyView: UIView {
    public var widthConstraint: NSLayoutConstraint?
    public var heightConstraint: NSLayoutConstraint?
    
    public var emptyImageView: UIImageView = UIImageView()
    public var contentLabel: UILabel = UILabel()
    public var inviteButton: UIButton = UIButton()

    
    func setupViews (){
        emptyImageView.translatesAutoresizingMaskIntoConstraints = false
//        emptyImageView.image = UIImage.ne_imageNamed(name: "icon_search_empty")
        addSubview(emptyImageView)
        NSLayoutConstraint.activate([
            emptyImageView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
            emptyImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: -80),
            emptyImageView.widthAnchor.constraint(equalToConstant: 153),
            emptyImageView.heightAnchor.constraint(equalToConstant: 72),
        ])
        
        contentLabel.translatesAutoresizingMaskIntoConstraints = false
//        contentLabel.text = "联系人未加入企业？"
        contentLabel.textColor = .normalSubTitleColor
        contentLabel.font = NEConstant.defaultTextFont(14)
        addSubview(contentLabel)
        
        NSLayoutConstraint.activate([
            contentLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor),
            contentLabel.topAnchor.constraint(equalTo: emptyImageView.bottomAnchor, constant: 24),
        ])

        inviteButton.translatesAutoresizingMaskIntoConstraints = false
        inviteButton.setTitle("去微信邀请", for: .normal)
        inviteButton.setTitleColor(.normalOrangeColor, for: .normal)
        inviteButton.titleLabel?.font = NEConstant.defaultTextFont(14)
//        inviteButton.addTarget(self, action: #selector(inviteToWechat), for: .touchUpInside)
        inviteButton.layer.cornerRadius = 15
        inviteButton.layer.borderWidth = 1
        inviteButton.layer.borderColor = UIColor.normalOrangeColor.cgColor
        self.addSubview(inviteButton)
        NSLayoutConstraint.activate([
            inviteButton.centerXAnchor.constraint(equalTo: self.centerXAnchor),
            inviteButton.topAnchor.constraint(equalTo: contentLabel.bottomAnchor, constant: 12),
            inviteButton.widthAnchor.constraint(equalToConstant: 102),
            inviteButton.heightAnchor.constraint(equalToConstant: 30),
        ])
    }

    
    init(imageName: String?, content: String, frame: CGRect) {
        super.init(frame: frame)
        self.setupViews()
        self.emptyImageView.image = UIImage.ne_imageNamed(name: imageName)
        self.contentLabel.text = content
    }
    
    init(image: UIImage?, content: String, frame: CGRect) {
        super.init(frame: frame)
        self.setupViews()
        self.emptyImageView.image = image
        self.contentLabel.text = content
    }
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 设置字符串
    /// - Parameter text: 字符串
    func setText(_ text: String?) {
        self.contentLabel.text = text
    }
    
    /// 设置富文本
    /// - Parameter att: 富文本
    func setAttributedText(_ att: NSAttributedString?) {
        self.contentLabel.attributedText = att
    }
    
    /// 设置占位图（根据图片名称，仅支持 NECommonUIKit 库中的图片）
    /// - Parameter name: （NECommonUIKit 库中的）图片名称
    func setEmptyImage(name: String?) {
        self.emptyImageView.image = UIImage.ne_imageNamed(name: name)
    }
    
    /// 设置占位图（支持外部传递）
    /// - Parameter image: 图片
    func setEmptyImage(image: UIImage?) {
        self.emptyImageView.image = image
    }
}
